<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="面试,">










<meta name="description" content="###鉴别出那瓶水有毒1234567891011121314151617有1000瓶水，其中有一瓶有毒，小白鼠只要尝一点带毒的水24小时后就会死亡，至少要多少只小白鼠才能在24小时时鉴别出那瓶水有毒链接：https://www.nowcoder.com/questionTerminal/84726a200b4a4a0d95b9565b4c6eb216来源：牛客网每个老鼠只有死或活2种状态，因此每个">
<meta name="keywords" content="面试">
<meta property="og:type" content="article">
<meta property="og:title" content="面试资料收集">
<meta property="og:url" content="http://yoursite.com/2019/02/28/面试资料收集/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:description" content="###鉴别出那瓶水有毒1234567891011121314151617有1000瓶水，其中有一瓶有毒，小白鼠只要尝一点带毒的水24小时后就会死亡，至少要多少只小白鼠才能在24小时时鉴别出那瓶水有毒链接：https://www.nowcoder.com/questionTerminal/84726a200b4a4a0d95b9565b4c6eb216来源：牛客网每个老鼠只有死或活2种状态，因此每个">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-01-10T12:26:20.179Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="面试资料收集">
<meta name="twitter:description" content="###鉴别出那瓶水有毒1234567891011121314151617有1000瓶水，其中有一瓶有毒，小白鼠只要尝一点带毒的水24小时后就会死亡，至少要多少只小白鼠才能在24小时时鉴别出那瓶水有毒链接：https://www.nowcoder.com/questionTerminal/84726a200b4a4a0d95b9565b4c6eb216来源：牛客网每个老鼠只有死或活2种状态，因此每个">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/02/28/面试资料收集/">



<meta name="referrer" content="never"> ​​​​


  <title>面试资料收集 | 苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/02/28/面试资料收集/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">面试资料收集</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-02-28T19:51:19+08:00">
                2019-02-28
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  5.5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  22 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>###鉴别出那瓶水有毒<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">有<span class="number">1000</span>瓶水，其中有一瓶有毒，小白鼠只要尝一点带毒的水<span class="number">24</span>小时后就会死亡，至少要多少只小白鼠才能在<span class="number">24</span>小时时鉴别出那瓶水有毒</span><br><span class="line">链接：https:<span class="comment">//www.nowcoder.com/questionTerminal/84726a200b4a4a0d95b9565b4c6eb216</span></span><br><span class="line">来源：牛客网</span><br><span class="line"></span><br><span class="line">每个老鼠只有死或活<span class="number">2</span>种状态，因此每个老鼠可以看作一个bit，取<span class="number">0</span>或<span class="number">1</span></span><br><span class="line">N个老鼠可以看作N个bit，可以表达<span class="number">2</span>^N种状态（其中第i个状态代表第i个瓶子有毒）</span><br><span class="line">例如：当N＝<span class="number">2</span>时，可以表达<span class="number">4</span>种状态</span><br><span class="line"><span class="number">0</span>，<span class="number">0</span>（ 一号老鼠活，二号老鼠活）</span><br><span class="line"><span class="number">0</span>，<span class="number">1</span>（ 一号老鼠活，二号老鼠死）</span><br><span class="line"><span class="number">1</span>，<span class="number">0</span>（ 一号老鼠死，二号老鼠活）</span><br><span class="line"><span class="number">1</span>，<span class="number">1</span>（ 一号老鼠死，二号老鼠死）</span><br><span class="line">具体来说，有A、B、C、D这<span class="number">4</span>个瓶子，一号老鼠喝A和B， 二号老鼠喝B和C</span><br><span class="line">如果 <span class="number">0</span>，<span class="number">0</span> （ 一号老鼠活，二号老鼠活），说明是D有毒，第<span class="number">0</span>个状态代表第<span class="number">4</span>个瓶子有毒</span><br><span class="line">如果 <span class="number">0</span>，<span class="number">1</span> （ 一号老鼠活，二号老鼠死） ，说明是C有毒 ，第<span class="number">1</span>个状态代表第<span class="number">3</span>个瓶子有毒</span><br><span class="line">如果 <span class="number">1</span>，<span class="number">0</span> （ 一号老鼠死，二号老鼠活） ，说明是A有毒 ，第<span class="number">2</span>个状态代表第<span class="number">1</span>个瓶子有毒</span><br><span class="line">如果 <span class="number">1</span>，<span class="number">1</span> （ 一号老鼠死，二号老鼠死） ，说明是B有毒 ，第<span class="number">3</span>个状态代表第<span class="number">2</span>个瓶子有毒</span><br><span class="line">可以想象成用<span class="number">2</span>进制来表示<span class="number">1000</span>个数最少需要多少位</span><br></pre></td></tr></table></figure></p>
<h3 id="Cookie-禁用了，Session-还能用吗"><a href="#Cookie-禁用了，Session-还能用吗" class="headerlink" title="Cookie 禁用了，Session 还能用吗"></a>Cookie 禁用了，Session 还能用吗</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">你第一次访问网站时，</span><br><span class="line">https:<span class="comment">//learnku.com/articles/25858 </span></span><br><span class="line">服务端脚本中开启了Sessionsession_start();，</span><br><span class="line"></span><br><span class="line">服务器会生成一个不重复的 SESSIONID 的文件session_id();，比如在/<span class="keyword">var</span>/lib/php/session目录</span><br><span class="line"></span><br><span class="line">并将返回(Response)如下的HTTP头 <span class="built_in">Set</span>-Cookie:PHPSESSIONID=xxxxxxx</span><br><span class="line"></span><br><span class="line">客户端接收到<span class="built_in">Set</span>-Cookie的头，将PHPSESSIONID写入cookie</span><br><span class="line"></span><br><span class="line">当你第二次访问页面时，所有Cookie会附带的请求头(Request)发送给服务器端</span><br><span class="line"></span><br><span class="line">服务器识别PHPSESSIONID这个cookie，然后去session目录查找对应session文件，</span><br><span class="line"></span><br><span class="line">找到这个session文件后，检查是否过期，如果没有过期，去读取Session文件中的配置；如果已经过期，清空其中的配置</span><br><span class="line">如果一个Cookie都没接收到，基本上可以预判客户端禁用了Cookie，那将session_id附带在每个网址后面(包括POST)，</span><br><span class="line">比如：</span><br><span class="line"></span><br><span class="line">GET http:<span class="comment">//www.xx.com/index.php?session_id=xxxxx</span></span><br><span class="line">POST http:<span class="comment">//www.xx.com/post.php?session_id=xxxxx</span></span><br><span class="line">然后在每个页面的开头使用session_id($_GET[<span class="string">'session_id'</span>])，来强制指定当前session_id</span><br><span class="line">所以Laravel等框架中，内部实现了Session的所有逻辑，并将PHPSESSIONID设置为httponly并加密，这样，前端JS就无法读取和修改这些敏感信息，降低了被盗用的风险。</span><br></pre></td></tr></table></figure>
<h3 id="如何进行防-SQL-注入"><a href="#如何进行防-SQL-注入" class="headerlink" title="如何进行防 SQL 注入"></a>如何进行防 SQL 注入</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span> 表单尽量用 post 提交,核心用户验证都走 post,避开 get容易暴露客户数据</span><br><span class="line"><span class="number">2</span> 使用HTTP_REFERER 检查源文件是否来自本系统</span><br><span class="line"><span class="number">3</span> 开启addslashes在特殊符号前加\</span><br><span class="line"><span class="number">4</span> 使用htmlspecialchars对字符串转实体</span><br><span class="line"><span class="number">5</span> 用户授权登录</span><br><span class="line"><span class="number">6</span> 使用PDO</span><br></pre></td></tr></table></figure>
<h3 id="大流量高并发量网站的解决方案"><a href="#大流量高并发量网站的解决方案" class="headerlink" title="大流量高并发量网站的解决方案"></a>大流量高并发量网站的解决方案</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">对比现实中饭店一下子同一个时间段来吃饭 比方中午https:<span class="comment">//learnku.com/articles/25886</span></span><br><span class="line"><span class="number">1</span> 把这个店面面积扩大点，增加同时吃饭人数</span><br><span class="line">   服务器优化：我们把apache服务器只支持（<span class="number">3000</span>并发）可以换成nginx服务器（<span class="number">3</span>w并发）</span><br><span class="line"><span class="number">2</span> 多找点服务员和厨师嘛  </span><br><span class="line">   服务器优化：修改apache，nginx的默认配置，把其中的并发数调到最高嘛</span><br><span class="line"><span class="number">3</span> 多开一些店 连锁店</span><br><span class="line">   服务器优化：多增加几台服务器同时对客户提供网络服务 lvs nginx 做负载均衡</span><br><span class="line"><span class="number">4</span> 限时客户在我们店吃饭的时间 不能让他们吃完还打牌把</span><br><span class="line">   服务器优化：减少客户在服务器上的连接断开时间 比方mysql 的连接断开时间 wait_timeout这个参数最多的连接时间 不能让客户恶意一直连着</span><br><span class="line"><span class="number">5</span> 给厨师培训 增加他的上菜时间</span><br><span class="line">   那就要给php代码做优化</span><br><span class="line"><span class="number">6</span> 让厨师叫手下把菜提前做好 放到冰箱里面</span><br><span class="line">   redis 缓存 文件缓存</span><br></pre></td></tr></table></figure>
<h3 id="sql分组"><a href="#sql分组" class="headerlink" title="sql分组"></a>sql分组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>) 算出每个班级中的学生，按照成绩降序排序;https:<span class="comment">//learnku.com/articles/25903#topnav</span></span><br><span class="line">select name,<span class="class"><span class="keyword">class</span>,<span class="title">score</span> <span class="title">from</span> <span class="title">student</span> <span class="title">order</span> <span class="title">by</span> <span class="title">class</span>,<span class="title">score</span> <span class="title">desc</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="number">2</span>) 查出每个班的及格人数和不及格人数，格式为:<span class="class"><span class="keyword">class</span>、及格人数、不及格人数</span>;</span><br><span class="line"></span><br><span class="line">SELECT <span class="class"><span class="keyword">class</span>,</span></span><br><span class="line"><span class="class"><span class="title">SUM</span>(<span class="title">CASE</span> <span class="title">WHEN</span> <span class="title">score</span>&gt;</span>=<span class="number">60</span> THEN <span class="number">1</span> ELSE <span class="number">0</span> END),</span><br><span class="line">SUM(CASE WHEN score&lt;<span class="number">60</span> THEN <span class="number">1</span> ELSE <span class="number">0</span> END)</span><br><span class="line">FROM tb1 GROUP BY <span class="class"><span class="keyword">class</span></span></span><br><span class="line"><span class="class">这边主要先分组 在聚合在加入判断条件</span></span><br><span class="line"><span class="class"></span></span><br><span class="line">3) 用 PHP 写入连接数据库("localhost","msuser","mspass")、执行以上 SQL、显示结果、 判断错误、关闭数据库的过程</span><br><span class="line">$conn=mysql_connect(‘localhost’,<span class="string">'msuser ’,’mspass′);//链接数据库</span></span><br><span class="line"><span class="string">Mysql_select_db(‘test’);</span></span><br><span class="line"><span class="string">$sql=" SELECT class,</span></span><br><span class="line"><span class="string">SUM(CASE WHEN score&gt;=60 THEN 1 ELSE 0 END), SUM(CASE WHEN score&lt;60 THEN 1 ELSE 0 END)</span></span><br><span class="line"><span class="string">FROM tb1 GROUP BY class";</span></span><br><span class="line"><span class="string">if($result=Mysql_query($sql))&#123;</span></span><br><span class="line"><span class="string">     while($row=mysql_fetch_assoc($result))&#123;</span></span><br><span class="line"><span class="string">     print_r($row);</span></span><br><span class="line"><span class="string">&#125; &#125;</span></span><br><span class="line"><span class="string">Mysql_close($conn);</span></span><br></pre></td></tr></table></figure>
<h3 id="GET-与-POST-的区别"><a href="#GET-与-POST-的区别" class="headerlink" title="GET 与 POST 的区别"></a>GET 与 POST 的区别</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">GET在浏览器回退时是无害的，而POST会再次提交请求。</span><br><span class="line">GET产生的URL地址可以被Bookmark，而POST不可以。</span><br><span class="line">GET请求会被浏览器主动cache，而POST不会，除非手动设置。</span><br><span class="line">GET请求只能进行url编码，而POST支持多种编码方式。</span><br><span class="line">GET请求参数会被完整保留在浏览器历史记录里，而POST中的参数不会被保留。</span><br><span class="line">GET请求在URL中传送的参数是有长度限制的，而POST么有。</span><br><span class="line">对参数的数据类型，GET只接受ASCII字符，而POST没有限制。</span><br><span class="line">GET比POST更不安全，因为参数直接暴露在URL上，所以不能用来传递敏感信息。</span><br><span class="line">GET参数通过URL传递，POST放在Request body中</span><br><span class="line"></span><br><span class="line">GET产生一个TCP数据包；POST产生两个TCP数据包。https:<span class="comment">//learnku.com/articles/25881</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">对于GET方式的请求，浏览器会把http header和data一并发送出去，服务器响应<span class="number">200</span>（返回数据）；</span><br><span class="line"></span><br><span class="line">而对于POST，浏览器先发送header，服务器响应<span class="number">100</span> <span class="keyword">continue</span>，浏览器再发送data，服务器响应<span class="number">200</span> ok（返回数据）。</span><br><span class="line"></span><br><span class="line">也就是说，GET只需要汽车跑一趟就把货送到了，而POST得跑两趟，第一趟，先去和服务器打个招呼“嗨，我等下要送一批货来，你们打开门迎接我”，然后再回头把货送过去。</span><br><span class="line"></span><br><span class="line">因为POST需要两步，时间上消耗的要多一点，看起来GET比POST更有效。因此Yahoo团队有推荐用GET替换POST来优化网站性能。但这是一个坑！跳入需谨慎。为什么？</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span> GET与POST都有自己的语义，不能随便混用。</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> 据研究，在网络环境好的情况下，发一次包的时间和发两次包的时间差别基本可以无视。而在网络环境差的情况下，两次包的TCP在验证数据包完整性上，有非常大的优点。</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> 并不是所有浏览器都会在POST中发送两次包，Firefox就只发送一次。</span><br><span class="line"></span><br><span class="line">浏览器有没有默认发送 Expect:<span class="number">100</span>-<span class="keyword">continue</span> 的请求头就不清楚, 但是 curl 是默认会发送的. 具体的解释可以看鸟哥的博客: http:<span class="comment">//www.laruence.com/2011/01/20/1840.html</span></span><br><span class="line"></span><br><span class="line">摘抄一下重点:</span><br><span class="line"></span><br><span class="line">在使用curl做POST的时候, 当要POST的数据大于<span class="number">1024</span>字节的时候, curl并不会直接就发起POST请求, 而是会分为俩步,</span><br><span class="line"></span><br><span class="line"> <span class="number">1.</span> 发送一个请求, 包含一个Expect:<span class="number">100</span>-<span class="keyword">continue</span>, 询问Server使用愿意接受数据</span><br><span class="line"> <span class="number">2.</span> 接收到Server返回的<span class="number">100</span>-<span class="keyword">continue</span>应答以后, 才把数据POST给Server</span><br><span class="line"></span><br><span class="line">并不是所有的Server都会正确应答<span class="number">100</span>-<span class="keyword">continue</span>, 比如lighttpd, 就会返回<span class="number">417</span> “Expectation Failed”, 则会造成逻辑出错.</span><br><span class="line">因此, 在使用 curl 时可以考虑增加一步处理, 既在请求头中将 Expect 值置空. 鸟哥给出的 demo 是这样</span><br><span class="line"></span><br><span class="line">curl_setopt($ch, CURLOPT_HTTPHEADER, array(<span class="string">'Expect:'</span>));</span><br><span class="line">guzzle 的做法是:</span><br><span class="line"></span><br><span class="line"><span class="comment">// If the Expect header is not present, prevent curl from adding it</span></span><br><span class="line"><span class="keyword">if</span> (!$request-&gt;hasHeader(<span class="string">'Expect'</span>)) &#123;</span><br><span class="line">    $conf[CURLOPT_HTTPHEADER][] = <span class="string">'Expect:'</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="nginx-配置"><a href="#nginx-配置" class="headerlink" title="nginx 配置"></a>nginx 配置</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">    # 监听 HTTP 协议默认的 [80] 端口。https://learnku.com/articles/25861</span><br><span class="line">    listen <span class="number">80</span>;</span><br><span class="line">    # 绑定主机名 [example.com]。</span><br><span class="line">    server_name example.com;</span><br><span class="line">    # 服务器站点根目录 [/example.com/public]。</span><br><span class="line">    root /example.com/public;</span><br><span class="line"></span><br><span class="line">    # 添加几条有关安全的响应头；与 Google+ 的配置类似，详情参见文末。</span><br><span class="line">    add_header X-Frame-Options <span class="string">"SAMEORIGIN"</span>;</span><br><span class="line">    add_header X-XSS-Protection <span class="string">"1; mode=block"</span>;</span><br><span class="line">    add_header X-Content-Type-Options <span class="string">"nosniff"</span>;</span><br><span class="line"></span><br><span class="line">    # 站点默认页面；可指定多个，将顺序查找。</span><br><span class="line">    # 例如，访问 http://example.com/ Nginx 将首先尝试「站点根目录/index.html」是否存在，不存在则继续尝试「站点根目录/index.htm」，以此类推...</span><br><span class="line">    index index.html index.htm index.php;</span><br><span class="line"></span><br><span class="line">    # 指定字符集为 UTF-8</span><br><span class="line">    charset utf<span class="number">-8</span>;</span><br><span class="line"></span><br><span class="line">    # Laravel 默认重写规则；删除将导致 Laravel 路由失效且 Nginx 响应 404。</span><br><span class="line">    location / &#123;</span><br><span class="line">        try_files $uri $uri/ <span class="regexp">/index.php?$query_string;</span></span><br><span class="line"><span class="regexp">    &#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">    # 关闭 [/favicon.ico] 和 [/robots.txt] 的访问日志。</span></span><br><span class="line"><span class="regexp">    # 并且即使它们不存在，也不写入错误日志。</span></span><br><span class="line"><span class="regexp">    location = /</span>favicon.ico &#123; access_log off; log_not_found off; &#125;</span><br><span class="line">    location = <span class="regexp">/robots.txt  &#123; access_log off; log_not_found off; &#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">    # 将 [404] 错误交给 [/index.php] 处理，表示由 Laravel 渲染美观的错误页面。</span></span><br><span class="line"><span class="regexp">    error_page 404 /i</span>ndex.php;</span><br><span class="line"></span><br><span class="line">    # URI 符合正则表达式 [\.php$] 的请求将进入此段配置</span><br><span class="line">    location ~ \.php$ &#123;</span><br><span class="line">        # 配置 FastCGI 服务地址，可以为 IP:端口，也可以为 Unix socket。</span><br><span class="line">        fastcgi_pass unix:<span class="regexp">/var/</span>run/php/php7<span class="number">.2</span>-fpm.sock;</span><br><span class="line">        # 配置 FastCGI 的主页为 index.php。</span><br><span class="line">        fastcgi_index index.php;</span><br><span class="line">        # 配置 FastCGI 参数 SCRIPT_FILENAME 为 $realpath_root$fastcgi_script_name。</span><br><span class="line">        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;</span><br><span class="line">        # 引用更多默认的 FastCGI 参数。</span><br><span class="line">        include fastcgi_params;</span><br><span class="line">    &#125;</span><br><span class="line">    # 通俗地说，以上配置将所有 URI 以 .php 结尾的请求，全部交给 PHP-FPM 处理。</span><br><span class="line"></span><br><span class="line">    # 除符合正则表达式 [/\.(?!well-known).*] 之外的 URI，全部拒绝访问</span><br><span class="line">    # 也就是说，拒绝公开以 [.] 开头的目录，[.well-known] 除外</span><br><span class="line">    location ~ <span class="regexp">/\.(?!well-known).* &#123;</span></span><br><span class="line"><span class="regexp">        deny all;</span></span><br><span class="line"><span class="regexp">    &#125;</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br></pre></td></tr></table></figure>
<p>###判断两个有序数组是否有公共元素<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// https://github.com/chunlintang/interview/blob/master/src/algorithms/common.php</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">common</span>(<span class="params">$arr1, $arr2</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	$len1 = count($arr1);</span><br><span class="line">	$len2 = count($arr2);</span><br><span class="line">	$common = [];</span><br><span class="line">	$i = $j = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span> ($i &lt; $len1 &amp;&amp; $j &lt; $len2) &#123;</span><br><span class="line">		<span class="keyword">if</span> ($arr1[$i] &gt; $arr2[$j]) &#123;</span><br><span class="line">			$j++;</span><br><span class="line">		&#125; elseif ($arr1[$i] &lt; $arr2[$j]) &#123;</span><br><span class="line">			$i++;</span><br><span class="line">		&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">			array_push($common, $arr1[$i]);</span><br><span class="line">			$i++;</span><br><span class="line">			$j++;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $common;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="猴子选大王，约瑟夫环"><a href="#猴子选大王，约瑟夫环" class="headerlink" title="猴子选大王，约瑟夫环"></a>猴子选大王，约瑟夫环</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// </span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">monkeyKing</span>(<span class="params">$n, $m</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	$arr = [<span class="number">1</span>, $n];</span><br><span class="line">	$i = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span> (count($arr) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">		$i++;</span><br><span class="line">		$survice = array_shift($arr);</span><br><span class="line">		<span class="keyword">if</span> ($i % $m != <span class="number">0</span>) &#123;</span><br><span class="line">			array_push($arr, $survice);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $arr[<span class="number">0</span>];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="质数"><a href="#质数" class="headerlink" title="质数"></a>质数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 质数</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">prime</span>(<span class="params">$n</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	$prime = [<span class="number">2</span>];</span><br><span class="line">	<span class="keyword">for</span> ($i = <span class="number">3</span>; $i &lt; $n; $i += <span class="number">2</span>) &#123;</span><br><span class="line">		$sqrt = intval(sqrt($i));</span><br><span class="line">		<span class="keyword">for</span> ($j = <span class="number">3</span>; $j &lt;= $sqrt; $j += <span class="number">2</span>) &#123;</span><br><span class="line">			<span class="keyword">if</span> ($i % $j == <span class="number">0</span>) &#123;</span><br><span class="line">				<span class="keyword">break</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> ($i &gt; $sqrt) &#123;</span><br><span class="line">			array_push($prime, $i);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $prime;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取所有的质数</span></span><br><span class="line"><span class="comment"> * @param array $arr</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_prime_number</span>(<span class="params">$arr = []</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 质数数组</span></span><br><span class="line">    $primeArr = [];</span><br><span class="line">    <span class="comment">// 循环所有备选数</span></span><br><span class="line">    foreach ($arr <span class="keyword">as</span> $value) &#123;</span><br><span class="line">        <span class="comment">// 备选数和备选数的中间数以下的数字整除比较</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">2</span>; $i &lt;= floor($value / <span class="number">2</span>); $i++) &#123;</span><br><span class="line">            <span class="comment">// 能够整除，则不是质数，退出循环</span></span><br><span class="line">            <span class="keyword">if</span> ($value % $i == <span class="number">0</span>) &#123;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 被除数$j比备选数的中间数大的则为质数</span></span><br><span class="line">        <span class="comment">// 这样判断的依据：</span></span><br><span class="line">        <span class="comment">// 假如备选数为质数，则内层的for循环不会break退出，则执行完毕，$i会继续+1，即最后$i = floor($value / 2) + 1</span></span><br><span class="line">        <span class="comment">// 假如备选数不为质数，则内层的for循环遇到整除就会break退出，$i不会继续+1，即最后$i &lt;= floor($value / 2)</span></span><br><span class="line">        <span class="keyword">if</span> ($value != <span class="number">1</span> &amp;&amp; $i &gt; floor($value / <span class="number">2</span>)) &#123;</span><br><span class="line">            $primeArr[] = $value;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $primeArr;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取所有的质数</span></span><br><span class="line"><span class="comment"> * @param array $arr</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_prime_number</span>(<span class="params">$arr = []</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 质数数组</span></span><br><span class="line">    $primeArr = [];</span><br><span class="line">    <span class="comment">// 循环所有备选数</span></span><br><span class="line">    foreach ($arr <span class="keyword">as</span> $value) &#123;</span><br><span class="line">        <span class="comment">// 备选数和备选数的中间数以下的数字整除比较</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">2</span>; $i &lt;= floor($value / $i); $i++) &#123;</span><br><span class="line">            <span class="comment">// 能够整除，则不是质数，退出循环</span></span><br><span class="line">            <span class="keyword">if</span> ($value % $i == <span class="number">0</span>) &#123;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 被除数$j比备选数的中间数大的则为质数</span></span><br><span class="line">        <span class="comment">// 这样判断的依据：</span></span><br><span class="line">        <span class="comment">// 假如备选数为质数，则内层的for循环不会break退出，则执行完毕，$i会继续+1，即最后$i = floor($value / $i) + 1</span></span><br><span class="line">        <span class="comment">// 假如备选数不为质数，则内层的for循环遇到整除就会break退出且$i不会继续+1，即最后$i &lt;= floor($value / $i)</span></span><br><span class="line">        <span class="keyword">if</span> ($value != <span class="number">1</span> &amp;&amp; $i &gt; floor($value / $i)) &#123;</span><br><span class="line">            $primeArr[] = $value;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $primeArr;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取所有的质数</span></span><br><span class="line"><span class="comment"> * @param array $arr</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">get_prime_number_three</span>(<span class="params">$arr = []</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 质数数组</span></span><br><span class="line">    $primeArr = $arr;</span><br><span class="line">    <span class="comment">// 循环所有备选数</span></span><br><span class="line">    foreach ($primeArr <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($value == <span class="number">1</span>) &#123;</span><br><span class="line">            unset($primeArr[$key]);</span><br><span class="line">            <span class="keyword">continue</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 备选数和备选数的中间数以下的数字整除比较</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">2</span>; $i &lt;= floor($value / $i); $i++) &#123;</span><br><span class="line">            <span class="comment">// 能够整除，则不是质数，从数组中删除且退出循环</span></span><br><span class="line">            <span class="keyword">if</span> ($value % $i == <span class="number">0</span>) &#123;</span><br><span class="line">                unset($primeArr[$key]);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 重置数组索引返回</span></span><br><span class="line">    <span class="keyword">return</span> array_values($primeArr);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 所有备选数数组</span></span><br><span class="line">$numberArr = range(<span class="number">1</span>, <span class="number">100</span>, <span class="number">1</span>);</span><br><span class="line"><span class="comment">// 获取备选数中的所有质数</span></span><br><span class="line">$primeNumberArr = get_prime_number($numberArr);</span><br><span class="line"><span class="comment">// 输出打印</span></span><br><span class="line">print_r($primeNumberArr);</span><br><span class="line"><span class="comment">// 所有备选数数组</span></span><br><span class="line">$numberArr = [<span class="number">11</span>, <span class="number">22</span>, <span class="number">33</span>, <span class="number">66</span>, <span class="number">77</span>, <span class="number">3</span>, <span class="number">8</span>, <span class="number">10</span>, <span class="number">99</span>];</span><br><span class="line"><span class="comment">// 获取备选数中的所有质数</span></span><br><span class="line">$primeNumberArr = get_prime_number($numberArr);</span><br><span class="line"><span class="comment">// 输出打印http://blog.y0701.com/2018/09/18/PHP%E7%AE%97%E6%B3%95%E4%B9%8B%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E8%B4%A8%E6%95%B0/</span></span><br><span class="line">print_r($primeNumberArr);</span><br></pre></td></tr></table></figure>
<h3 id="PHP算法之二分查找"><a href="#PHP算法之二分查找" class="headerlink" title="PHP算法之二分查找"></a>PHP算法之二分查找</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 二分查找算法</span></span><br><span class="line"><span class="comment"> * @param array $arr 待查找区间</span></span><br><span class="line"><span class="comment"> * @param int $number 查找数</span></span><br><span class="line"><span class="comment"> * @return int        返回找到的键</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">binary_search</span>(<span class="params">$arr, $number</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 非数组或者数组为空，直接返回-1</span></span><br><span class="line">    <span class="keyword">if</span> (!is_array($arr) || empty($arr)) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 初始变量值</span></span><br><span class="line">    $len = count($arr);</span><br><span class="line">    $lower = <span class="number">0</span>;</span><br><span class="line">    $high = $len - <span class="number">1</span>;</span><br><span class="line">    <span class="comment">// 最低点比最高点大就退出</span></span><br><span class="line">    <span class="keyword">while</span> ($lower &lt;= $high) &#123;</span><br><span class="line">        <span class="comment">// 以中间点作为参照点比较</span></span><br><span class="line">        $middle = intval(($lower + $high) / <span class="number">2</span>);</span><br><span class="line">        <span class="keyword">if</span> ($arr[$middle] &gt; $number) &#123;</span><br><span class="line">            <span class="comment">// 查找数比参照点小，舍去右边</span></span><br><span class="line">            $high = $middle - <span class="number">1</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($arr[$middle] &lt; $number) &#123;</span><br><span class="line">            <span class="comment">// 查找数比参照点大，舍去左边</span></span><br><span class="line">            $lower = $middle + <span class="number">1</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">// 查找数与参照点相等，则找到返回</span></span><br><span class="line">            <span class="keyword">return</span> $middle;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 未找到，返回-1</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @param array $arr 待查找区间</span></span><br><span class="line"><span class="comment"> * @param int $number 查找数</span></span><br><span class="line"><span class="comment"> * @param int $lower 区间最低点</span></span><br><span class="line"><span class="comment"> * @param int $high 区间最高点</span></span><br><span class="line"><span class="comment"> * @return int</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">binary_search_recursion</span>(<span class="params">&amp;$arr, $number, $lower, $high</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 以区间的中间点作为参照点比较</span></span><br><span class="line">    $middle = intval(($lower + $high) / <span class="number">2</span>);</span><br><span class="line">    <span class="comment">// 最低点比最高点大就退出</span></span><br><span class="line">    <span class="keyword">if</span> ($lower &gt; $high) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ($number &gt; $arr[$middle]) &#123;</span><br><span class="line">        <span class="comment">// 查找数比参照点大，舍去左边继续查找</span></span><br><span class="line">        <span class="keyword">return</span> binary_search_recursion($arr, $number, $middle + <span class="number">1</span>, $high);</span><br><span class="line">    &#125; elseif ($number &lt; $arr[$middle]) &#123;</span><br><span class="line">        <span class="comment">// 查找数比参照点小，舍去右边继续查找</span></span><br><span class="line">        <span class="keyword">return</span> binary_search_recursion($arr, $number, $lower, $middle - <span class="number">1</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> $middle;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 待查找区间</span></span><br><span class="line">$arr = [<span class="number">1</span>, <span class="number">3</span>, <span class="number">7</span>, <span class="number">9</span>, <span class="number">11</span>, <span class="number">57</span>, <span class="number">63</span>, <span class="number">99</span>];</span><br><span class="line"><span class="comment">// 非递归查找66所在的位置</span></span><br><span class="line">$find_key = binary_search($arr, <span class="number">57</span>);</span><br><span class="line"><span class="comment">// 递归查找66所在的位置</span></span><br><span class="line">$find_key_r = binary_search_recursion($arr, <span class="number">57</span>, <span class="number">0</span>, count($arr));</span><br><span class="line"><span class="comment">// 输出打印</span></span><br><span class="line">print_r($find_key);</span><br><span class="line">print_r($find_key_r);http:<span class="comment">//blog.y0701.com/2018/09/20/PHP%E7%AE%97%E6%B3%95%E4%B9%8B%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE/</span></span><br></pre></td></tr></table></figure>
<h3 id="UTF-8编码"><a href="#UTF-8编码" class="headerlink" title="UTF-8编码"></a>UTF-8编码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">Unicode只是一个符号集，它只规定了符号的二进制代码，却没有规定这个二进制代码应该如何存储。</span><br><span class="line"></span><br><span class="line">汉字”严”的unicode是十六进制数<span class="number">4E25</span>，转换成二进制数足足有<span class="number">15</span>位（<span class="number">100111000100101</span>），也就是说这个符号的表示至少需要<span class="number">2</span>个字节。表示其他更大的符号，可能需要<span class="number">3</span>个字节或者<span class="number">4</span>个字节，甚至更多。</span><br><span class="line"></span><br><span class="line">UTF<span class="number">-8</span>就是在互联网上使用最广的一种Unicode的实现方式。其他实现方式还包括UTF<span class="number">-16</span>（字符用两个字节或四个字节表示）和UTF<span class="number">-32</span>（字符用四个字节表示），不过在互联网上基本不用。重复一遍，这里的关系是，UTF<span class="number">-8</span>是Unicode的实现方式之一。</span><br><span class="line"></span><br><span class="line">UTF<span class="number">-8</span>最大的一个特点，就是它是一种变长的编码方式。它可以使用<span class="number">1</span>~<span class="number">4</span>个字节表示一个符号，根据不同的符号而变化字节长度。</span><br><span class="line">Unicode转义字符让我们可以通过Unicode码点输入特殊的字符。 有两种形式：\uhhhh对应<span class="number">16</span>bit的码点值， \Uhhhhhhhh对应<span class="number">32</span>bit的码点值， 其中h是一个十六进制数字；一般很少需要使用<span class="number">32</span>bit的形式。 每一个对应码点的UTF8编码。 例如：下面的字母串面值都表示相同的值：</span><br><span class="line"> </span><br><span class="line"><span class="string">"世界"</span></span><br><span class="line"><span class="string">"\xe4\xb8\x96\xe7\x95\x8c"</span></span><br><span class="line"><span class="string">"\u4e16\u754c"</span></span><br><span class="line"><span class="string">"\U00004e16\U0000754c"</span></span><br><span class="line">上面三个转义序列都为第一个字符串提供替代写法， 但是它们的值都是相同的。</span><br><span class="line">打开”记事本”程序Notepad.exe，新建一个文本文件，内容就是一个”严”字，依次采用ANSI，Unicode，Unicode big endian 和 UTF<span class="number">-8</span>编码方式保存。</span><br><span class="line">然后，用文本编辑软件UltraEdit中的”十六进制功能”，观察该文件的内部编码方式。</span><br><span class="line"></span><br><span class="line">ANSI：文件的编码就是两个字节”D1 CF”，这正是”严”的GB2312编码，这也暗示GB2312是采用大头方式存储的。</span><br><span class="line">Unicode：编码是四个字节”FF FE <span class="number">25</span> <span class="number">4</span>E”，其中”FF FE”表明是小头方式存储，真正的编码是<span class="number">4E25</span>。</span><br><span class="line">Unicode big endian：编码是四个字节”FE FF <span class="number">4</span>E <span class="number">25</span>″，其中”FE FF”表明是大头方式存储。</span><br><span class="line">UTF<span class="number">-8</span>：编码是六个字节”EF BB BF E4 B8 A5″，前三个字节”EF BB BF”表示这是UTF<span class="number">-8</span>编码，后三个”E4B8A5″就是”严”的具体编码，它的存储顺序与编码顺序是一致的。</span><br><span class="line">注意，windows下通过记事本保存的utf8默认是带BOM的utf，而一般建议都是使用不带BOM的utf8编码https:<span class="comment">//xin053.github.io/2016/09/07/UTF-8%E7%BC%96%E7%A0%81/</span></span><br></pre></td></tr></table></figure>
<h3 id="缓存穿透缓存击穿缓存雪崩"><a href="#缓存穿透缓存击穿缓存雪崩" class="headerlink" title="缓存穿透缓存击穿缓存雪崩"></a>缓存穿透缓存击穿缓存雪崩</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">缓存穿透 ： DB 承受了没有必要的查询流量，意思就是查到空值的时候没有做缓存处理，再次查询的时候继续读库了</span><br><span class="line">缓存击穿：热点 Key，大量并发读请求引起的小雪崩， 就是缓存在某个时间点过期的时候，恰好在这个时间点对这个 Key 有大量的并发请求过来，这些请求发现缓存过期一般都会从后端 DB 加载数据并回设到缓存，这个时候大并发的请求可能会瞬间把后端 DB 压垮</span><br><span class="line">缓存雪崩：缓存设置同一过期时间，引发的大量的读取数据库操作</span><br></pre></td></tr></table></figure>
<h3 id=""><a href="#" class="headerlink" title=" "></a> </h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><a href="https://learnku.com/articles/39504" target="_blank" rel="noopener">python 后端开发面经</a></p>
<p><a href="https://www.kancloud.cn/explore" target="_blank" rel="noopener">看云文档</a></p>
<p><a href="https://learnku.com/php/t/38272" target="_blank" rel="noopener">PHP 面试题和答案</a></p>
<p><a href="https://www.kancloud.cn/kancloud/a-programmer-prepares/78223" target="_blank" rel="noopener">程序员的自我修养</a></p>
<p><a href="https://github.com/wudi/PHP-Interview-Best-Practices-in-China" target="_blank" rel="noopener">PHP 面试知识点汇总</a></p>
<p><a href="https://learnku.com/articles/25837" target="_blank" rel="noopener">正向代理为客户端做代理，反向代理为服务器做代理</a></p>
<p><a href="https://juejin.im/post/5ac05aab6fb9a028e25db037" target="_blank" rel="noopener">计算机网络知识总结</a></p>
<p><a href="https://juejin.im/post/5ac49b5c518825556e5e5060" target="_blank" rel="noopener">排序算法全总结</a></p>
<p><a href="https://juejin.im/post/5ad6e4066fb9a028d82c4b66" target="_blank" rel="noopener">面试中关于Redis的问题看这篇就够了</a></p>
<p><a href="https://juejin.im/post/5b192314e51d45067d407822" target="_blank" rel="noopener">Mysql锁机制简单了解一下</a></p>
<p><a href="https://juejin.im/post/5c1731466fb9a049af6d2a83" target="_blank" rel="noopener">消息队列其实很简单</a></p>
<p><a href="https://juejin.im/post/5ba591386fb9a05cd31eb85f" target="_blank" rel="noopener">一份最适合你的后端面试指南</a></p>
<p><a href="https://juejin.im/post/5b4977ae5188251b146b2fc8" target="_blank" rel="noopener">面试必备之乐观锁与悲观锁</a></p>
<p><a href="https://juejin.im/post/5b7be0b2e51d4538db34a51e" target="_blank" rel="noopener">搞定计算机网络面试，看这篇就够了</a></p>
<p><a href="https://juejin.im/post/5b59c9f6e51d4535a65add84" target="_blank" rel="noopener">程序员简历之道</a></p>
<p><a href="https://juejin.im/post/5b3b19856fb9a04fa42f8c71" target="_blank" rel="noopener">前端&amp;后端程序员必备的Linux基础知识</a></p>
<p><a href="https://github.com/Snailclimb/programmer-advancement" target="_blank" rel="noopener">技术人员成长必备！</a></p>
<p><a href="https://juejin.im/post/5b2dffb851882574eb598896" target="_blank" rel="noopener">技术面试中常见的几道智力题 </a></p>
<p><a href="https://juejin.im/post/5b24cf7e51882574c020bd56" target="_blank" rel="noopener">关于MySQL的知识点与面试常见问题都在这里</a></p>
<p><a href="https://github.com/Snailclimb/JavaGuide" target="_blank" rel="noopener">一份涵盖大部分Java程序员所需要掌握的核心知识</a></p>
<p><a href="https://github.com/chunlintang/interview" target="_blank" rel="noopener">php面试</a></p>
<p><a href="https://www.qingwei.tech/somehub/" target="_blank" rel="noopener">图标生成器</a></p>
<p><a href="https://www.qingwei.tech/programe-develops/1171.html" target="_blank" rel="noopener">程序猿面试应知道的8种数据结构</a></p>
<p><a href="https://juejin.im/post/5c368a7df265da612e28d5c7" target="_blank" rel="noopener">历经 20 天，我终于完成了这份专为程序员编写的英语学习指南</a></p>
<p><a href="https://learnku.com/articles/27430#topnav" target="_blank" rel="noopener">如何”有计划，高效率，优简历”应对面试</a></p>
<p><a href="https://wdxtub.com/interview/14520847747820.html" target="_blank" rel="noopener">小土刀的面试刷题笔记</a></p>
<p><a href="https://segmentfault.com/a/1190000018378234" target="_blank" rel="noopener">我本以为你们会写简历</a></p>
<p> <a href="https://learnku.com/articles/27738#topnav" target="_blank" rel="noopener">《数据结构与算法之美》复杂度分析</a></p>
<p><a href="https://haoruijie.art/2019/04/02/book-soft-skill-review.html" target="_blank" rel="noopener">《软技能：代码之外的生存准则》读后感</a></p>
<p><a href="https://juejin.im/post/5c96fb795188252d5f0fdff2?utm_source=coffeephp.com" target="_blank" rel="noopener">Redis和mysql数据怎么保持数据一致的</a></p>
<p><a href="https://segmentfault.com/a/1190000011405320" target="_blank" rel="noopener">Nginx高并发下的优化</a></p>
<p><a href="https://github.com/HIT-Alibaba/interview" target="_blank" rel="noopener">笔试面试知识整理</a></p>
<p><a href="https://learnku.com/laravel/t/6138/share-some-of-the-problems-that-larvel-and-phper-interviews-may-encounter" target="_blank" rel="noopener">PHPer 面试可能会遇到的问题</a></p>
<p><a href="https://learnku.com/articles/25842" target="_blank" rel="noopener">画江湖之算法篇【排序算法】冒泡排序</a></p>
<p><a href="https://www.imooc.com/learn/696" target="_blank" rel="noopener">从零开始打造自己的PHP框架 </a></p>
<p><a href="https://github.com/nonfu/laravel-tutorial-code" target="_blank" rel="noopener">Laravel 从入门到精通教程代码</a></p>
<p><a href="https://laravelacademy.org/laravel-tutorial-5_7" target="_blank" rel="noopener">Laravel 从入门到精通系列教程</a></p>
<p><a href="https://laravelacademy.org/programmer-internal-skills-series" target="_blank" rel="noopener">程序员内功修炼系列 2019 版</a></p>
<p><a href="https://github.com/xianyunyh/PHP-Interview" target="_blank" rel="noopener"> PHP 面试的资料</a></p>
<p><a href="https://learnku.com/articles/17867" target="_blank" rel="noopener">简聊 Session 与 Token 身份验证</a></p>
<p><a href="https://learnku.com/articles/25814" target="_blank" rel="noopener">画江湖之数据结构【第二话:队列】队列</a></p>
<p><a href="https://learnku.com/articles/22363" target="_blank" rel="noopener">面试前必须要知道的 Redis 面试内容</a></p>
<p><a href="https://learnku.com/articles/20031" target="_blank" rel="noopener">【简易图解】『 OAuth2.0』 猴子都能懂的图解</a></p>
<p><a href="https://learnku.com/articles/25070#topnav" target="_blank" rel="noopener">面试之 Redis 基础、高级特性与性能调优</a></p>
<p><a href="https://learnku.com/articles/22538" target="_blank" rel="noopener">收集的干货，持续更新</a></p>
<p><a href="https://segmentfault.com/a/1190000018447170?utm_source=tag-newest" target="_blank" rel="noopener">PHP面试常考之设计模式——建造者模式</a></p>
<p><a href="https://learnku.com/articles/25252#topnav" target="_blank" rel="noopener">PHP 详细面试总结 (二 HTTP 请求全过程)</a></p>
<p><a href="https://www.fanhaobai.com/2017/09/lua.html" target="_blank" rel="noopener">lua</a></p>
<p><a href="https://learnku.com/articles/26686" target="_blank" rel="noopener">代理与反向代理、负载均衡和缓存</a></p>
<p><a href="https://segmentfault.com/a/1190000018464303?utm_source=tag-newest" target="_blank" rel="noopener">PHP-FPM 与 Nginx 的通信机制总结</a></p>
<p><a href="http://fanqieto.top/2018/08/03/%E4%BB%8E%E4%B8%80%E9%81%93%E7%99%BE%E5%BA%A6%E9%9D%A2%E8%AF%95%E9%A2%98%E8%AF%B4%E8%B5%B7/" target="_blank" rel="noopener">从一道百度面试题说起</a></p>
<p><a href="http://fanqieto.top/2018/07/26/%E7%AC%94%E8%AF%95%E9%9D%A2%E8%AF%95%E5%B8%B8%E7%94%A8%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95%E6%80%BB%E7%BB%93/" target="_blank" rel="noopener">笔试面试常用排序算法总结</a></p>
<p><a href="https://learnku.com/articles/25204" target="_blank" rel="noopener">PHP 详细面试总结</a></p>
<p><a href="http://fanqieto.top/2018/06/23/%E9%9D%A2%E8%AF%95%E7%9A%84%E6%8A%80%E5%B7%A7%EF%BC%88%E4%B8%8A%EF%BC%89%EF%BC%9A%E5%90%AC%E6%87%82%E5%88%AB%E4%BA%BA%E7%9A%84%E9%97%AE%E9%A2%98/" target="_blank" rel="noopener">面试的技巧（上）：听懂别人的问题</a></p>
<p><a href="http://fanqieto.top/2018/06/17/%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E9%97%AE%E9%A2%98%E5%85%B6%E5%AE%9E%E6%9C%80%E5%B8%B8%E8%A7%81/" target="_blank" rel="noopener">leetcode题解（数组问题）</a></p>
<p><a href="http://fanqieto.top/2018/06/14/%E7%AE%97%E6%B3%95%E9%9D%A2%E8%AF%95%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E4%B9%88%E9%AC%BC/" target="_blank" rel="noopener">如何准备算法面试</a></p>
<p><a href="http://fanqieto.top/2017/10/12/%E9%AB%98%E5%B9%B6%E5%8F%91%E4%B8%8B%E7%BB%99%E6%95%B0%E6%8D%AE%E5%BA%93%E6%80%A7%E8%83%BD%E6%9C%89%E5%93%AA%E4%BA%9B%E5%BD%B1%E5%93%8D/" target="_blank" rel="noopener">高并发下给数据库性能有哪些影响？</a></p>
<p><a href="http://blog.thankbabe.com/2018/05/23/shared-experience/#top" target="_blank" rel="noopener">大话后端开发的奇淫技巧大集合</a></p>
<p><a href="https://zhuanlan.zhihu.com/p/26175433" target="_blank" rel="noopener">聪明人应该如何背英语单词？</a></p>
<p><a href="http://www.sangeng.org/blog/detail_563.html" target="_blank" rel="noopener">20K+的高级PHP面试题汇总</a></p>
<p><a href="https://mp.weixin.qq.com/s/OzAnRVPUDtoiIXqeC7YL6g" target="_blank" rel="noopener">阿里云Redis开发规范 </a></p>
<p><a href="https://www.cnblogs.com/walblog/articles/8476579.html" target="_blank" rel="noopener">php解决高并发问题</a></p>
<p><a href="https://learnku.com/laravel/t/24359" target="_blank" rel="noopener">面试最让你手足无措的一个问题：你的系统如何支撑高并发</a></p>
<p><a href="https://learnku.com/articles/25879" target="_blank" rel="noopener">面试 (MySQL 索引为啥要选择 B+ 树)</a></p>
<p><a href="https://github.com/XiaoMi/soar/blob/master/doc/heuristic.md" target="_blank" rel="noopener">MySQL 避坑宝典</a></p>
<p><a href="https://learnku.com/articles/24795#topnav" target="_blank" rel="noopener">深入 Nginx 之配置篇</a></p>
<p><a href="https://learnku.com/articles/28716" target="_blank" rel="noopener">PHP 面试踩过的坑</a></p>
<p><a href="https://learnku.com/articles/28772" target="_blank" rel="noopener">PHP 面试详解之技术篇</a></p>
<p><a href="http://blog.y0701.com/2018/09/11/PHP%E9%9D%A2%E8%AF%95%E6%80%BB%E7%BB%93/" target="_blank" rel="noopener">PHP面试总结</a></p>
<p><a href="https://github.com/duiying/php-notes" target="_blank" rel="noopener">记录开发或面试中可能遇到的知识点</a></p>
<p><a href="http://qinghua.github.io/encoding-and-escaping/" target="_blank" rel="noopener">程序员常见的编码和转义</a></p>
<p><a href="https://betacat.online/posts/2019-01-25/what-happens-when-you-type-googlecom-into-your-browser-and-return/" target="_blank" rel="noopener">当你在浏览器中输入“google.com”并回车，会发生什么</a></p>
<p><a href="https://betacat.online/posts/2019-02-22/reverse-proxy-and-intranet-through/" target="_blank" rel="noopener">反向代理和内网穿透frp ngrok</a></p>
<p><a href="https://learnku.com/articles/29685" target="_blank" rel="noopener">TCP 协议简单说明</a></p>
<p><a href="https://learnku.com/articles/28896" target="_blank" rel="noopener">最近去腾讯面试了，分享一波面试题</a></p>
<p><a href="https://github.com/xianyunyh/PHP-Interview" target="_blank" rel="noopener">PHP面试准备的资料</a></p>
<p><a href="https://learnku.com/articles/21993#replies" target="_blank" rel="noopener">2019年小米春季上海 PHP 实习生招聘面试题</a></p>
<p><a href="https://github.com/0voice/interview_internal_reference" target="_blank" rel="noopener">2019年最新总结，阿里，腾讯，百度，美团，头条等技术面试题目</a></p>
<p><a href="https://github.com/guanhui07/studyFiles" target="_blank" rel="noopener">一些电子书pdf</a></p>
<p><a href="https://learnku.com/articles/33612" target="_blank" rel="noopener">php面试</a></p>
<p><a href="https://learnku.com/articles/33806" target="_blank" rel="noopener">PHP 三年模拟五年面试之一网打尽系列（4）—– MySQL 高级</a></p>
<p><a href="https://learnku.com/articles/35779" target="_blank" rel="noopener">整理有关面试普遍问题和回答技巧</a></p>
<p><a href="https://learnku.com/articles/36719" target="_blank" rel="noopener">到底该学习什么编程语言</a></p>
<p><a href="https://learnku.com/articles/32343#replies" target="_blank" rel="noopener">PHP7 底层运行机制</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/面试/" rel="tag"># 面试</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/02/26/python代码段收集/" rel="next" title="python代码段收集">
                <i class="fa fa-chevron-left"></i> python代码段收集
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/03/01/那些黑科技/" rel="prev" title="那些黑科技">
                那些黑科技 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
          <div class="comments" id="comments">
             <div id="gitment-container"></div>
         </div>
  




        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Cookie-禁用了，Session-还能用吗"><span class="nav-number">1.</span> <span class="nav-text">Cookie 禁用了，Session 还能用吗</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#如何进行防-SQL-注入"><span class="nav-number">2.</span> <span class="nav-text">如何进行防 SQL 注入</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#大流量高并发量网站的解决方案"><span class="nav-number">3.</span> <span class="nav-text">大流量高并发量网站的解决方案</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sql分组"><span class="nav-number">4.</span> <span class="nav-text">sql分组</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#GET-与-POST-的区别"><span class="nav-number">5.</span> <span class="nav-text">GET 与 POST 的区别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#nginx-配置"><span class="nav-number">6.</span> <span class="nav-text">nginx 配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#猴子选大王，约瑟夫环"><span class="nav-number">7.</span> <span class="nav-text">猴子选大王，约瑟夫环</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#质数"><span class="nav-number">8.</span> <span class="nav-text">质数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#PHP算法之二分查找"><span class="nav-number">9.</span> <span class="nav-text">PHP算法之二分查找</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#UTF-8编码"><span class="nav-number">10.</span> <span class="nav-text">UTF-8编码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#缓存穿透缓存击穿缓存雪崩"><span class="nav-number">11.</span> <span class="nav-text">缓存穿透缓存击穿缓存雪崩</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#"><span class="nav-number">12.</span> <span class="nav-text"> </span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
